package com.base.cn.platform.os.controller.op.giftcard;

import com.base.cn.platform.os.common.AdminBaseController;
import com.base.cn.platform.os.common.log.aop.AdminModuleEnum;
import com.base.cn.platform.os.common.log.aop.OpLog;
import com.base.cn.platform.os.service.manage.op.giftcard.OpGiftCardService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.math.BigDecimal;
import java.util.Map;

/**
 * 礼品卡
 * @author ll
 * @date 2018/5/14 11:39
 */
@Controller
@RequestMapping("/admin/op/giftCard")
public class AdminOpGiftCardController extends AdminBaseController {

    @Autowired
    private OpGiftCardService opGiftCardService;

    /**
     * 去添加页面
     * @return
     */
    @RequestMapping("/toSaveOpGiftCardPage")
    public String toSaveOpGiftCardPage(){
        return resultPage("/op/giftcard/giftcard_create");
    }


    /**
     * 去列表页面
     * @return
     */
    @RequestMapping("/toOpGiftCardListPage")
    public String toOpGiftCardListPage(Model model,
                                     @RequestParam(value = "other",required = false,defaultValue = "0")Integer other){
        model.addAttribute("other",other);
        return resultPage("/op/giftcard/giftcard_list");
    }


    /**
     * 分页搜索礼品卡
     * @param opCoupon
     * @param currentPage
     * @return
     */
    @RequestMapping("/queryGiftCardListPage")
    public String queryGiftCardListPage(Model model,
                                        @RequestBody Map<String, Object> opCoupon,
                                        @RequestParam(value = "other",required = false,defaultValue = "0")Integer other,
                                        @RequestParam(value = "currentPage",required = false,defaultValue = "1")Integer currentPage){
        Map<String,Object> dataMap =opGiftCardService.queryGiftCardListPage(currentPage,opCoupon,true);
        model.addAttribute("dataMap",dataMap);
        model.addAttribute("other",other);
        return resultPage("/op/giftcard/giftcard_ajax_list");
    }

    /**
     * 新建礼品卡
     * @param giftCard
     * @return
     */
    @RequestMapping("/saveOpGiftCard")
    @ResponseBody
    @OpLog(module = AdminModuleEnum.OTHER, action = "新建礼品卡")
    public Map<String,Object> saveOpGiftCard(@RequestBody Map<String,Object> giftCard){
        return opGiftCardService.saveGiftCard(giftCard);
    }

    /**
     * 修改状态
     * @param giftCardIds
     * @param status
     * @return
     */
    @RequestMapping("/updateOpGiftCardStatus")
    @ResponseBody
    @OpLog(module = AdminModuleEnum.OTHER, action = "修改礼品卡状态")
    public Map<String,Object> updateOpGiftCardStatus(@RequestParam("giftCardIds")String giftCardIds,
                                                   @RequestParam("status")Integer status){
        return opGiftCardService.updateStatusByIds(giftCardIds,status);
    }




    /**
     * 查看详情页面
     * @param giftCardId 礼品卡Id
     * @return
     */
    @RequestMapping("/queryOpGiftCardById")
    public String queryOpGiftCardById(Model model,
                                      @RequestParam("giftCardId")BigDecimal giftCardId){
        Map<String,Object> giftCard =opGiftCardService.queryOpGiftCardById(giftCardId,true);
        model.addAttribute("giftCard",giftCard);
        return  resultPage("/op/giftcard/giftcard_info");
    }


    /**
     * 赠送GiftCard礼品卡
     * @param userIds
     * @return
     */
    @RequestMapping("/presentGiftCard")
    @ResponseBody
    @OpLog(module = AdminModuleEnum.OTHER, action = "赠送学员礼品卡")
    public Map<String,Object> presentGiftCard(@RequestParam("userIds")String userIds,
                                              @RequestParam("giftCardId")BigDecimal giftCardId){
        return opGiftCardService.presentGiftCard(userIds,giftCardId);
    }

    /**
     * 分页搜索礼品卡
     * @param opCoupon
     * @param currentPage
     * @return
     */
    @RequestMapping("/queryGiftCardSelectListPage")
    public String queryGiftCardSelectListPage(Model model,
                                        @RequestBody Map<String, Object> opCoupon,
                                        @RequestParam(value = "currentPage",required = false,defaultValue = "1")Integer currentPage){
        opCoupon.put("status",1);
        opCoupon.put("isExchange",true);
        Map<String,Object> dataMap =opGiftCardService.queryGiftCardListPage(currentPage,opCoupon,true);
        model.addAttribute("dataMap",dataMap);
        return resultPage("/op/giftcard/giftcard_ajax__service_list");
    }
}
